package com.wangy.mapper;

import com.wangy.bean.MonitorDetail;
import com.wangy.bean.SchedulerJobInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author yyzb
 * @date 2024/12/30 19:30
 */
@Mapper
public interface SchedulerMapper {

    @Select("SELECT * FROM scheduler_job_info")
    List<SchedulerJobInfo> getAllJobs();

    @Insert("insert into scheduler_job_info(jobName, jobGroup, jobStatus, repeatTime, jobClass, cronJob, cronExpression, jobType) VALUES " +
            "(#{jobName}, #{jobGroup}, #{jobStatus}, #{repeatTime}, #{jobClass}, #{cronJob}, #{cronExpression}, #{jobType})")
    void addJob(SchedulerJobInfo jobInfo);

    @Update("UPDATE scheduler_job_info SET jobStatus = '已暂停' WHERE jobName = #{jobName} AND jobGroup = #{jobGroup}")
    void pauseJob(SchedulerJobInfo jobInfo);

    @Update("UPDATE scheduler_job_info SET jobStatus = '运行中' WHERE jobName = #{jobName} AND jobGroup = #{jobGroup}")
    void resumeJob(SchedulerJobInfo jobInfo);

    @Delete("DELETE FROM scheduler_job_info WHERE id = #{id}")
    void deleteJob(SchedulerJobInfo jobInfo);

//    @Select("select 100.0 * count(#{fieldName}) / count(1) from #{tableName}")
    Double computeNullRate(String tableName, String fieldName);

    @Insert("INSERT INTO mysql_data_monitor (database_name, table_name, field_name, field_null_rate) VALUES " +
            "(#{databaseName}, #{tableName}, #{fieldName}, #{fieldNullRate})")
    void insertRecord(MonitorDetail monitorDetail);
}
